<?php
    $id = $_GET['id'];
    $fechaI = "'" . $_GET['fechaI'] . "'";
    $fechaF =  $_GET['fechaF'];
    $sql = "SELECT dispositivos.AsignadoA,
                    idDato,Fecha,FechaSend,Latitude,Longitude,codigos.Codigo 
                    FROM datosge INNER JOIN dispositivos
                    ON datosge.idDispositivo=dispositivos.idDispositivo				
                    INNER JOIN codigos
                    ON datosge.Codigo=codigos.idCodigo
                    WHERE  datosge.idDispositivo = ? and FechaSend >= " . $fechaI . "  and FechaSend <= '" . $fechaF ." 23:59:59'";
    $query = $this->db->query($sql, array($id));
    $num_rows = $query->num_rows($query);
    $row1 = $query->result_array();
 ?>
<!DOCTYPE html>
<html>
    <head>
        <title>POS Mobile - Reporte Recorrido</title>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
        <!-- Bootstrap -->
        <link href="<?php echo base_url(); ?>css/bootstrap.css" rel="stylesheet">
        <link href="<?php echo base_url(); ?>css/bootstrap.min.css" rel="stylesheet">
        <link href="<?php echo base_url(); ?>css/icons-set.css" rel="stylesheet">
        <link href="<?php echo base_url(); ?>css/style.css" rel="stylesheet">
        <!-- Fonts -->
        <link href='http://fonts.googleapis.com/css?family=Alef' rel='stylesheet' type='text/css'>
        <script src="<?php echo base_url(); ?>js/jquery.js"></script>
        <style>
            #nodatos{
                width:50%;
                position:absolute;
                top:100px;
                left:225px;
                border:none;
                padding: 20px;
                z-index: 1;
            }
        </style>
        <script type="text/javascript" language="javascript" src="<?php echo base_url(); ?>js/jquery.dataTables.js"></script>           
        <script type='text/javascript'>
            var n;
            function getAddress(campo)
            {
                n=campo;
                var aux=document.getElementById('bodyTable').getElementsByTagName('tr').length;
                if(n<aux)
                {
                    var td=document.getElementById("dir"+campo);
                    var datos=td.className.split(',');
                    getCAlleA(datos[0],datos[1],td);
                    n+=1;
                    setTimeout('getAddress(n)',1200);
                }
            }

            function getCAlleA(lat,lon,td){
                $.ajax({
                    type: "GET",
                    url: "webservice/WebService/getDireccion",
                    data: "lat="+lat+"&lon="+lon,
                    dataType: "html",
                    contentType: "application/x-www-form-urlencoded",
                    success: function(datos1){
                        td.innerHTML=datos1;
                    }
                });
            } 
            
            $(document).ready(function() {
            $('#tablaPosiciones').dataTable( {
                "bFilter": false,
                "bPaginate": false,
                "sScrollY": "250px",
                "bSort": true,
                "iDisplayLength": 10,
                "oLanguage": {
                        "oPaginate": {
                            "sFirst": "Primera",
                            "sLast": "&Uacuteltima",
                            "sNext": "Siguiente",
                            "sPrevious": "Anterior"
                        },
                     "sEmptyTable": "No hay datos disponibles.",
                     "sInfo": "Se muestran _START_ a _END_ de _TOTAL_ previos.",
                     "sInfoEmpty": "Se muestran 0 a 0 de 0 previos.",
                     "sInfoFiltered": "(Filtrados de _MAX_ total de previos)",
                     "sLengthMenu": "Se muestran _MENU_ previos",
                     "sLoadingRecords": "Cargando informaci&oacute;n...",
                     "sProcessing": "Procesando...",
                     "sSearch": "Buscar:",
                     "sZeroRecords": "No se encuentran coincidencias"
                    }
              } );
            } );
        </script>              
    </head>
            <body onload="getAddress(0)" style="width:95%; margin:0 auto;">
                <?php if(count($row1) == 0 ){ ?>
                    <div id="nodatos" >
                        <img src="<?php echo base_url(); ?>/img/nodatos.png" />
                    </div>
                <?php } else { ?>
                
                    <div id="logo" class="pull-left" style="height:50px; margin-top: 10px;">
                        <img src="<?php echo base_url(); ?>/img/POSMobile.png"/>
                    </div>
                    
                    <div id="datos" class="pull-right well" style="height:50px; margin-top: 10px;">
                        <p class="span3 btn-info headTable text-center"><?php echo $row1[0]['AsignadoA'];?></p><br />
                        <p class="span3 text-center"><small>Del <?php echo $this->input->get('fechaI');?> al <?php echo $this->input->get('fechaI');?></small></p>
                    </div>
                    <div class="clearfix"></div>
                    <div id="tabla">
                        <table  id="tablaPosiciones" class="table table-striped table-condensed" style="width:100%">
                            <thead class="headTable">
                                <tr class="headTable">
                                    <th class="span2"><center>Fecha</center></th>
                                    <th class="span2"><center>C&oacute;digo</center></th>
                                    <th class="span3"><center>Direcci&oacute;n</center></th>
                                </tr>
                            </thead>
                            <tbody id="bodyTable" style="font-size: 11px;">
                                    <?php

                                        $i = 0;
                                        foreach ($row1 as $row) { ?>
                                            <tr id="<?php echo $row['idDato']; ?>">
                                                <td><center><?php echo $row['Fecha']; ?></center></td>
                                                <td><center><?php echo $row['Codigo']; ?></center></td>                              
                                                <td id="<?php echo 'dir' . $i;
                                            $i++; ?>" class="<?php echo $row['Latitude'] . ',' . $row['Longitude']; ?>"><center></center></td>          
                                            </tr>
                                        <?php }?>

                            </tbody>
                        </table>
                    </div>
                 <?php } ?>
        </body>  
</html>